Arduino Uno L298N Dual Motor Controller: Industrial Drive System

Professional L298N dual full-H-bridge IC drives two independent DC motors (5-46V, 2A continuous/3A peak) with independent PWM speed control and direction via 7 Arduino digital pins. 4N75 Darlington arrays provide 2.5V drop maintaining 78% efficiency at 12V/1A typical robotics loads.

IN1/IN2 (pins 8,7) control Motor A direction; IN3/IN4 (pins 4,2) control Motor B. ENA/ENB (pins 9,10 PWM) regulate 0-100% speed. 5V regulator powers Arduino; enable pin jumper selectable.

How It Works

A microcontroller pin can source perhaps 20 mA; a small DC motor draws hundreds of milliamps and several amps when stalled. A motor driver bridges that gap, and it also solves a second problem the pin cannot: reversing the motor requires reversing the current through it, which a single output cannot do.

The answer is an H-bridge — four switches arranged so that closing one diagonal pair drives the motor one way and the other pair drives it the other. The L298N contains two such bridges, so it drives two DC motors independently or one stepper.

Each channel takes two direction pins and one enable pin. The direction pins select forward, reverse or brake; the enable pin accepts PWM, and its duty cycle sets speed. This separation is why an L298N needs three pins per motor.

The L298N is an old bipolar design and drops roughly 2 V across its output stage, so a 6 V supply delivers only about 4 V to the motor and the difference becomes heat. Modern MOSFET drivers such as the TB6612FNG or DRV8833 lose a fraction of that and run cool.

Components Needed

  • Arduino Uno
  • L298N Dual H-Bridge Motor Driver Module
  • 2x 6-12V DC motors (1A stall max)
  • 12V 2A switching power supply
  • Heavy-duty jumper wires (18AWG motor)
  • Screw terminal motor connections

Wiring to the Arduino Uno

Connect ENA to D9, IN1 and IN2 to D2 and D3, and repeat for channel B. Motor power goes to +12V and GND, and the driver ground must be tied to the board ground — without a common reference the logic inputs float and the motors behave randomly.

The onboard 5 V regulator jumper matters. With it fitted and a supply above 7 V, the module generates 5 V that can power the microcontroller. Remove it if you are supplying 5 V externally, or the two regulators fight.

The 5 V logic of this board matches the L298N input thresholds directly.

Driver pinArduino Uno pinFunction
ENAD9PWM speed control, motor A
IN1 / IN2D2 / D3Direction, motor A
ENB / IN3 / IN4Three more pinsMotor B
+12VMotor supply +Motor power, 7–35 V
GNDSupply GND and board GNDShared reference — essential
+5V—Regulator output, or input if jumper removed

Example Code

Bidirectional speed control for one motor with explicit brake and coast. Upload it with the board set to Arduino Uno and open the Serial Monitor at 9600 baud.

Bidirectional speed control for one motor with explicit brake and coast
const int ENA = 9;
const int IN1 = 2;
const int IN2 = 3;

void drive(int speed) {            // -255 .. +255
  bool forward = (speed >= 0);
  int magnitude = constrain(abs(speed), 0, 255);

  digitalWrite(IN1, forward ? HIGH : LOW);
  digitalWrite(IN2, forward ? LOW  : HIGH);
  analogWrite(ENA, magnitude);
}

void brake() {                     // both inputs high shorts the motor
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, HIGH);
  analogWrite(ENA, 255);
}

void coast() { analogWrite(ENA, 0); }

void setup() {
  Serial.begin(9600);
  pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT);
  coast();
}

void loop() {
  Serial.println("forward, ramping up");
  for (int s = 60; s <= 255; s += 5) { drive(s); delay(40); }
  delay(800);

  Serial.println("brake");   brake();  delay(500);
  Serial.println("reverse"); drive(-180); delay(1500);
  Serial.println("coast");   coast();  delay(1000);
}

Applications

A l298n motor driver turns up in a wide range of projects. These are the uses where it is the right choice rather than a compromise:

  • Two-wheel and four-wheel robot drive systems
  • Conveyor and linear actuator control
  • Reversible pumps and fans
  • Driving a bipolar stepper motor using both bridges
  • Any DC motor needing both speed and direction control

Working with the Arduino Uno

The Arduino Uno is built around the ATmega328P and runs on 5 V logic with 2 KB of SRAM and 32 KB of program flash. These details change how this circuit is wired and what the sketch can do, so they are worth stating plainly before you build.

The Uno runs at 5 V, so most hobby sensor modules connect directly with no level shifting.

With only 2 KB of SRAM, avoid large buffers and prefer the F() macro for constant strings.

The single hardware UART is shared with the USB connection, so heavy Serial printing competes with uploads.

Arduino Uno characteristicValueWhy it matters here
Logic voltage5 VMatches most hobby modules directly
ADC resolution10-bit (0–1023)Sets how finely an analog reading can be resolved
Analog inputsA0–A5 (six channels)Determines how many analog sensors can share the board
PWM outputsD3, D5, D6, D9, D10 and D11Needed for brightness, speed and tone control
I²C pinsA4 (SDA) and A5 (SCL)Fixed by hardware — wiring copied from another board may not match
Interrupt pinsD2 and D3 onlyRequired for counting fast or asynchronous events
Seriala single hardware UART shared with USBMonitor runs at 9600 baud by default

Troubleshooting

Most problems with this module fall into a handful of categories. Work through these before suspecting the part itself:

  • Motors twitch randomly — the driver and board grounds are not connected.
  • The motor runs but the board resets — motor current is being drawn through the board supply. Use a separate supply for motors.
  • The driver gets very hot — normal for an L298N, but check the heatsink is fitted and the current is within rating.
  • The motor is weaker than expected — the L298N drops about 2 V; raise the supply or switch to a MOSFET driver.
  • Speed control does nothing — ENA is on a non-PWM pin, or the enable jumper is still fitted, tying it permanently high.
  • One direction works and the other does not — one direction pin is not connected or is on a failed output.
  • Code written for an ESP board gives odd analog values — the Arduino Uno uses a 10-bit ADC returning 0–1023; rescale any constant taken from a 12-bit example.
  • An I²C sensor is not found after copying wiring from another Arduino — on the Arduino Uno I²C is on A4 (SDA) and A5 (SCL).

Taking It Further on the Arduino Uno

Once the basic reading works, where you go next depends very much on which board you are using. These are the directions that suit the Arduino Uno specifically:

The Uno’s shield ecosystem is its real advantage. Once the circuit works on a breadboard, a prototyping shield turns it into something permanent that still stacks with a data-logging or Ethernet shield without rewiring.

Logging to an SD card via a shield is the natural next step, since the Uno has no onboard storage and no network. Timestamp each reading with a DS3231 real-time clock so the log survives power cuts with correct times.

Because SRAM is limited to 2 KB, keep logged strings short and write them out immediately rather than buffering. Building a long String in memory is the most common cause of an Uno sketch that runs for hours and then freezes.

Notes and Practical Limits

Always start motors from a non-zero minimum. Below roughly 20% duty most DC motors buzz without turning, which wastes current and can overheat the driver — the sketch starts its ramp at 60 for that reason.

Brake and coast are genuinely different. Brake shorts the windings so the motor resists turning; coast disconnects and lets it spin freely. Robots that need to stop precisely should brake, not coast.